package com.hj.hos.config;

import com.hj.hos.service.*;
import com.hj.hos.HosService;
import com.hj.hos.enums.HosTypeEnum;
import com.hj.hos.properties.HosProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hj
 * @Date 2023/4/29
 * @Description: 存储配置文件
 */
@Configuration
@EnableConfigurationProperties(HosProperties.class)
@ConditionalOnProperty(prefix = "hos", value = "enabled")
public class HosInjectConfig {

    @Bean
    public HosService storageService(HosProperties properties) {
        HosTypeEnum typeEnum = properties.getConfig().getType();
        if (typeEnum == HosTypeEnum.LOCAL) {
            return new LocalHosService(properties);
        } else if (typeEnum == HosTypeEnum.ALIYUN) {
            return new AliyunHosService(properties);
        }else if (typeEnum == HosTypeEnum.HUAWEI) {
            return new HuaweiHosService(properties);
        }else if (typeEnum == HosTypeEnum.MINIO) {
            return new MinioHosService(properties);
        }else if (typeEnum == HosTypeEnum.QINIU) {
            return new QiniuHosService(properties);
        } else if (typeEnum == HosTypeEnum.TENCENT) {
            return new TencentHosService(properties);
        }
        return null;
    }

}
